<!--
 * @Author: your name
 * @Date: 2021-12-07 14:41:47
 * @LastEditTime: 2022-02-16 15:21:46
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \web-vue\src\components\HelloWorld.vue
-->
<template>
  <el-container>
    <el-aside width="200px">
      <side-menu></side-menu>

    </el-aside>
    <el-container>
      <el-header>
        <strong>后台管理系统</strong>
        <div class="header-avator">
          <el-avatar size="medium" :src="userInfo.avatar"></el-avatar>

          <el-dropdown>
            <span class="el-dropdown-link">
              {{userInfo.username}}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <router-link to="/userCenter">
                  个人中心
                </router-link>
              </el-dropdown-item>
              <el-dropdown-item @click.native="logout">
                退出
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>

          <el-link href="" target="_blank">网站</el-link>
          <el-link href="https://space.bilibili.com/7392483/fans/follow?tagid=442949" target="_blank">B站</el-link>
        </div>
      </el-header>
      <el-main>
        <Tabs></Tabs>
        <div style="margin:0 15px;">
        <router-view></router-view>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import SideMenu from './inc/SideMenu.vue'
import Tabs from './inc/Tabs.vue'

export default {
  name: "Home",
  components: { SideMenu,Tabs },
  data() {
    return {
      userInfo: {
        id: "",
        username: "",
        avatar: ""
      }
    }

  },
  // 页面一旦渲染出来就调用created内容
  created() {
    this.getUserInfo()

  },
  methods: {
    getUserInfo() {
      this.$axios.get("/sys/userInfo").then(res => {
        this.userInfo = res.data.data
      })
    },
    logout() {
      this.$axios.post("/logout").then(res => {
        localStorage.clear()
        sessionStorage.clear()

        this.$store.commit("resetState")

        this.$router.push("/login")
      })
    }
  }

}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.el-container {
  padding: 0;
  margin: 0;
  height: 100%;
}
.header-avator {
  float: right;
  width: 210px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.el-header,
.el-footer {
  background-color: #17b3a3;
  color: #333;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  color: #333;
  padding:0;
}

.el-dropdown-link {
  cursor: pointer;
}
.el-icon-arrow-down {
  font-size: 12px;
}

a {
  text-decoration: none;
}

</style>
